<?php

namespace App\Models;

use App\Libs\DataFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ClaimProject extends Model
{

    use DataFormat;

    protected $table = 'claim_project';
    protected $dates = [''];

    public static  $projectStatus = ['1'=>'未开始', '2'=>'认领中', '3'=>'已结束'];

    public static  $formatKey = ['id'=>'int', 'team_name'=>'string',  'logo'=>'image_url',  'name'=>'string',  'address'=>'string',  'begin'=>'string',  'end'=>'string',  'cover'=>'image_url',  'banner'=>'json_decode',  'publish_time'=>'string', 'content'=>'string', ];

    public function getAllInfo()
    {
        $data = ClaimProject::format($this);
        $data['claim_status'] = ClaimProject::projectStatus($this);

        foreach($data['banner'] as $key=>$value)
        {
            $data['banner'][$key] = image_url($value);
        }
        return $data;
    }


    public static function projectStatus($project)
    {

        if(date('Y-m-d') < $project->begin)
        {
            return 1;
        }elseif(date('Y-m-d') <= $project->end)
        {
            return 2;
        }else
        {
            return 3;
        }
    }

    public function org()
    {
        return $this->hasOne('App\Models\Org', 'id', 'org_id');
    }
}
